package com.LeeCode;

/**
 * 得到 K 个黑块的最少涂色次数
 */

public class Code2379 {
    public static void main(String[] args) {
        String blocks = "WBWBBBW";
        int k = 2;
        System.out.println(new Code2379().minimumRecolors(blocks, k));

    }

    public int minimumRecolors(String blocks, int k) {
        int curNum = 0, maxNum = 0;
        for (int i = 0; i < blocks.length(); i++) {
            if (blocks.charAt(i) == 'B') {
                curNum++;
            }
            if (i < k - 1) {
                continue;
            }
            maxNum = Math.max(maxNum, curNum);

            if (maxNum == k) {
                break;
            }

            if (blocks.charAt(i - k + 1) == 'B') {
                curNum--;
            }
        }
        return k - maxNum;
    }
}
